﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using EnvDTE;
using EnvDTE80;

namespace SinacorRules
{
    public sealed class Rule_InterfaceNamespaceShouldMatchGuidelines : BaseAddIn.Rules.BaseRuleAddIn
    {
        public Rule_InterfaceNamespaceShouldMatchGuidelines()
            : base("BovespaInterfaceNamespaceShouldMatchGuidelines",
                   "SinacorRules.SinacorRules",
                   typeof(Rule_InterfaceNamespaceShouldMatchGuidelines).Assembly)
        {
        }

        protected sealed override void Check(CodeInterface2 inter)
        {
            CodeAttribute atributo;
            string valor;
            string namespacePadrao = "\"http://www.bovespa.com.br/Sinacor.Servico.{0}.Service.ServiceContract\"";
            FileInfo fileInfo;

            for (int i = 1; i <= inter.Attributes.Count; i++)
            {
                atributo = (CodeAttribute)inter.Attributes.Item(i);

                if (atributo.Name == "ServiceContract")
                {
                    valor = atributo.Value;
                    fileInfo = new FileInfo(inter.StartPoint.Parent.Parent.FullName);

                    if (!valor.Contains(String.Format(namespacePadrao, fileInfo.Directory.Parent.Parent.Name)))
                    {
                        GeraProblemaAddIn(atributo.StartPoint.Parent.Parent.FullName,
                                         atributo.StartPoint.Line,
                                         atributo.StartPoint.DisplayColumn,
                                         "InterfaceNamespaceShouldMatchGuidelinesResolution",
                                         inter.Name,
                                         inter.Namespace.Name);
                    }
                }
            }
        }
    }
}
